package com.itheima.test;


import com.tanhua.autoconfig.template.AipFaceTemplate;
import com.tanhua.server.AppServerApplication;
import org.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baidu.aip.face.AipFace;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.HashMap;
@SpringBootTest(classes = AppServerApplication.class)
@RunWith(SpringRunner.class)
public class facetest {
    @Autowired
    AipFaceTemplate aipFaceTemplate;
    //设置APPID/AK/SK
    public static final String APP_ID = "117947053";
    public static final String API_KEY = "rMwKDoerRyFckn35l711UEkZ";
    public static final String SECRET_KEY = "KHodh2NhzMLB5UHItFefGrtCxLtO1mY9";

    public static void main(String[] args) {
        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);


        // 调用接口
        String image = "https://whctanhua.oss-cn-beijing.aliyuncs.com/2025/03/09/0124b32e-1084-4da6-9b34-2f1fd7bcc9de.png";
        String imageType = "URL";
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "LOW");

        // 人脸检测
        JSONObject res = client.detect(image, imageType, options);
        System.out.println(res.toString(2));
      String error_code =  String.valueOf(res.get("error_code"));
      System.out.println(error_code);

    }
    @Test
    public void testoss2(){
     Boolean face =  aipFaceTemplate.face("https://whctanhua.oss-cn-beijing.aliyuncs.com/2025/03/09/0124b32e-1084-4da6-9b34-2f1fd7bcc9de.png");
     System.out.println(face);
    }

}
